<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Banners extends OC_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('banner_model', 'bm');
		/*$this->load->model('categories/category_model', 'ctm');
		$this->load->model('subcategories/subcategory_model', 'sctm');*/
	}
	
	function _remap($method, $params = array()) {
		parent::_remap($method, $params);
		
		if (method_exists($this, $method)) return call_user_func_array(array(
			$this,
			$method
		) , $params);
		else show_404();
	}
	
	function init_header() {
		$this->header['jeasyui'] = TRUE;
		$this->header['source_top'] = array(
			link_tag(site_url('banners/themescript/uploader/css/jquery.fileupload.css')),
			link_tag(site_url('banners/themescript/uploader/css/jquery.fileupload-ui.css'))
		);
		
		$this->header['source_bot'] = array(
			script_tag(site_url('banners/themescript/uploader/js/load-image.js')),
			script_tag(site_url('banners/themescript/uploader/js/canvas-to-blob.js')),
			script_tag(site_url('banners/themescript/uploader/js/tmpl.js')),
			script_tag(site_url('banners/themescript/uploader/js/vendor/jquery.ui.widget.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.iframe-transport.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.fileupload.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.fileupload-process.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.fileupload-image.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.fileupload-validate.js')),
			script_tag(site_url('banners/themescript/uploader/js/jquery.fileupload-ui.js')),
			script_tag(site_url('banners/themescript/jquery.number.js')),
			script_tag(site_url('banners/themescript/app/banners.js'))
		);
	}
	
	function index() {
		$this->init_header();
		
		$this->header['nav'] = 'banners';
		$this->header['pagetitle'] = 'Banners';
		
		$this->view('banners/banners_view');
	}
	
	function load_data() {
		$params = $this->input->post();
		$result = $this->bm->get_all($params);
		
		print (json_encode($result));
	}
	
	function load_images($banners_id) {
		$images = $this->bm->get_images($banners_id);
		
		if (count($images) > 0) {
			if (!empty($images[0]->b_filename)) {
				$params['images'] = count($images) > 0 ? array_chunk($images, 3) : $images;
				print ($this->load->view('banners/banners_galery_view', $params, TRUE));
				return;
			}
		}
		
		print ('');
	}
	
	function save_data() {
		$post = $this->input->post();
		unset($post['files']);
		
		if (empty($post['b_id'])) {
			$post['b_created_date'] = date('Y-m-d H:i:s');
			unset($post['b_id']);
			$this->bm->add($post);
		} else {
			$post['b_modified_date'] = date('Y-m-d H:i:s');
			$this->bm->edit($post, array(
				'b_id' => $post['b_id']
			));
		}
		
		print (json_encode(array(
			'success' => TRUE
		)));
	}
	
	function delete_data() {
		$post = $this->input->post();
		$this->bm->delete(array(
			'b_id' => $post['b_id']
		));
		
		print (json_encode(array(
			'success' => TRUE
		)));
	}
	
	function delete_image() {
		$keys = $this->input->post();
		$this->bm->delete_img($keys);
		print (json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file banners.php */
/* Location: .//D/private/oemahcode/dnetnorfintek/module_admin/banners/controllers/banners.php */